package com.daxia.bumall.service;

import java.util.Calendar;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.daxia.bumall.dao.UserStatisticsDAO;
import com.daxia.bumall.dto.UserStatisticsDTO;
/**
 * 用户统计
 * @author elvis
 *
 */
@Service
public class UserStatisticsService {

	@Autowired
	private UserStatisticsDAO userStatisticsDAO;
	/**
	 * 统计当天登录用户
	 * @return
	 */
	public UserStatisticsDTO statisticsUserToday(){
		return userStatisticsDAO.statisticsUserByDate(new Date());
	}
	/**
	 * 统计昨天登录用户
	 * @return
	 */
	public UserStatisticsDTO statisticsUserYesterday(){
		Calendar cal=Calendar.getInstance();
		cal.setTime(new Date());
		cal.add(Calendar.DATE, -1);
		return userStatisticsDAO.statisticsUserByDate(new Date(cal.getTimeInMillis()));
	}
	/**
	 * 统计当前月的登录用户
	 * @return
	 */
	public UserStatisticsDTO statisticsUserMoth(){
		Calendar cal=Calendar.getInstance();
		cal.setTime(new Date());
		cal.set(Calendar.DAY_OF_MONTH, 1);
		return userStatisticsDAO.statisticsUserByDate(cal.getTime(),null);
	}
	/**
	 * 统计上月登录用户
	 * @return
	 */
	public UserStatisticsDTO statisticsUserLastMonth(){
		Calendar cal=Calendar.getInstance();
		cal.setTime(new Date());
		cal.add(Calendar.MONTH, -1);
		cal.set(Calendar.DATE, 1);
		Date startTime=cal.getTime();
		cal.add(Calendar.MONTH, 1);
		Date endTime=cal.getTime();
		return userStatisticsDAO.statisticsUserByDate(startTime, endTime);
	}
}
